package morenoapp.model.impl.index;

import morenoapp.model.data.MorenoAnswerFace;
import morenoapp.model.data.MorenoAnswerItemFace;
import morenoapp.model.data.MorenoMeasureFace;
import morenoapp.model.data.MorenoModelFace;
import morenoapp.model.data.MorenoQuestionFace;
import morenoapp.model.data.MorenoRespondentFace;
import morenoapp.model.index.MorenoRespondentIndex;

/**
 *
 * @author dmitry.mamonov
 */
public class MorenoRespondentSentPreferencesWeightIndexImpl 
        extends MorenoQuestionDerivedIndexImpl
        implements MorenoRespondentIndex {
    MorenoMeasureFace measure;
    public MorenoRespondentSentPreferencesWeightIndexImpl(MorenoModelFace _model, String _type, MorenoQuestionFace _question, MorenoMeasureFace _measure) {
        super(_model, _type, _question);
        this.measure = _measure;
    }

    @Override
    public double getIndexValue(MorenoRespondentFace _resp) {
        double weight = 0.0;
        MorenoAnswerFace answer = _resp.getAnswerByQuestion(getQuestion());
        for(MorenoAnswerItemFace item:answer.getAnswerItems()){
            if (item.getTarget()!=null){
                weight+=measure.getWeight(item.getQuestionItem().getItemNumber());
            }
        }
        return weight;
    }
}
